# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
from cerbero.tools.libtool import LibtoolLibrary

class Recipe(recipe.Recipe):
    name = 'pango'
    version = '1.42.4'
    stype = SourceType.TARBALL
    btype = BuildType.MESON
    url = 'gnome://'
    tarball_checksum = '1d2b74cd63e8bd41961f2f8d952355aa0f9be6002b52c8aa7699d9f5da597c9d'
    licenses = [License.LGPLv2Plus]
    deps = ['cairo', 'fontconfig', 'freetype', 'fribidi', 'harfbuzz']
    patches = [
        # https://gitlab.gnome.org/GNOME/pango/merge_requests/23
        name + '/0001-meson-Don-t-run-help2man-when-cross-building.patch',
        # Cherry-picked from upstream master
        name + '/0001-meson-fix-build-on-osx.patch',
        # https://gitlab.gnome.org/GNOME/pango/merge_requests/24
        name + '/0001-meson-Set-the-compatibility-version-correctly-on-mac.patch',
        # https://gitlab.gnome.org/GNOME/pango/-/merge_requests/181
        name + '/0001-meson-Fix-check-for-builtype-arguments.patch',
        name + '/0001-pangowin32-fontmap-read-windows-fallbacks-from-regis.patch',
        # https://gitlab.gnome.org/GNOME/pango/-/merge_requests/34
        name + '/0002-win32-Use-GPrivate-managed-display-device-context.patch', 
        # https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/574
    ]

    files_libs = ['libpangocairo-1.0', 'libpango-1.0', 'libpangoft2-1.0']
    files_bins = ['pango-view']
    files_devel = ['include/pango-1.0',
        'lib/pkgconfig/pangoft2.pc', 'lib/pkgconfig/pango.pc',
        'lib/pkgconfig/pangocairo.pc']
    platform_files_libs = {
        Platform.WINDOWS: ['libpangowin32-1.0'],
    }
    platform_files_devel = {
        Platform.WINDOWS: ['lib/pkgconfig/pangowin32.pc'],
        Platform.LINUX: ['lib/pkgconfig/pango.pc'],
    }
    files_typelibs = [
        'Pango-1.0',
        'PangoCairo-1.0',
        'PangoFT2-1.0'
        ]

    def post_install(self):
        LibtoolLibrary('pango-1.0', None, None, None, self.config.libdir,
                self.config.target_platform, deps=['gobject-2.0', 'fribidi']).save()
        LibtoolLibrary('pangoft2-1.0', None, None, None, self.config.libdir,
                self.config.target_platform, deps=['pango-1.0', 'harfbuzz', 'fontconfig', 'expat', 'freetype', 'bz2', 'png16']).save()
        LibtoolLibrary('pangocairo-1.0', None, None, None, self.config.libdir,
                self.config.target_platform, deps=['pango-1.0', 'cairo', 'pixman-1', 'pangoft2-1.0']).save()
        if self.config.target_platform == Platform.WINDOWS:
            LibtoolLibrary('pangowin32-1.0', None, None, None, self.config.libdir,
                    self.config.target_platform, deps=['pango-1.0', 'cairo']).save()
        super().post_install()
